# -*- coding: utf-8 -*-
# @Author    : Tian Wencheng
# @CreateTime: 2021/1/10 17:05
# @FileName  : data_analysis.py
# @IDE       : PyCharm
# @Git       : https://gitee.com/dianetian/projects


from common.request import HTTPRequest
from interface.base import BaseModule


class DataAnalysis(BaseModule):
    def __init__(self):
        self.request_url = ""
        self.request_method = ""
        self.request_headers = {"Content-Type": "application/json"}
        self.request_params = None
        self.cookies = super().cookies
        self.web_url = super().web_url

    def get_people_count_statistics(self, **kwargs):
        start_time = kwargs.get("startTime")
        end_time = kwargs.get("endTime")
        start_time_bucket = kwargs.get("startTimeBucket")
        end_time_bucket = kwargs.get("endTimeBucket")
        interval = kwargs.get("interval")

        self.request_url = "/api/data/passenger_analysis"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"startTime": start_time, "endTime": end_time, "startTimeBucket": start_time_bucket,
                               "endTimeBucket": end_time_bucket, "interval": interval}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_people_density_statistics(self, **kwargs):
        start_time = kwargs.get("startTime")
        end_time = kwargs.get("endTime")
        interval = kwargs.get("interval")

        self.request_url = "/api/realtime/density"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"startTime": start_time, "endTime": end_time, "interval": interval}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_people_density_top(self, **kwargs):
        start_time = kwargs.get("startTime")
        end_time = kwargs.get("endTime")
        interval = kwargs.get("interval")

        self.request_url = "/api/top/density"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"startTime": start_time, "endTime": end_time, "interval": interval}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_people_flow_statistics(self, **kwargs):
        start_time = kwargs.get("startTime")
        end_time = kwargs.get("endTime")
        interval = kwargs.get("interval")

        self.request_url = "/api/realtime/statistics"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"startTime": start_time, "endTime": end_time, "interval": interval}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_people_flow_top(self, **kwargs):
        start_time = kwargs.get("startTime")
        end_time = kwargs.get("endTime")
        interval = kwargs.get("interval")

        self.request_url = "/api/top/holding"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"startTime": start_time, "endTime": end_time, "interval": interval}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_train_start_stop_detail(self, **kwargs):
        start_time = kwargs.get("startTime")
        end_time = kwargs.get("endTime")
        current_page = kwargs.get("currentTime")
        areas = kwargs.get("area[]")
        page_size = kwargs.get("pageSize")
        event_type_id = kwargs.get("eventTypeId")

        self.request_url = "/api/data/trainStartAndStopList"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"startTime": start_time, "endTime": end_time, "currentPage": current_page,
                               "area[]": areas, "pageSize": page_size, "eventTypeId": event_type_id}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_camera_image_quality(self, **kwargs):
        start_time = kwargs.get("startTime")
        end_time = kwargs.get("endTime")
        areas = kwargs.get("area[]")

        self.request_url = "/api/manager/deviceImageQuality"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"startTime": start_time, "endTime": end_time, "area[]": areas}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_camera_image_quality_detail(self, **kwargs):
        start_time = kwargs.get("startTime")
        end_time = kwargs.get("endTime")
        device_name = kwargs.get("deviceName")
        malfunction_type = kwargs.get("malfunctionType")
        current_page = kwargs.get("currentPage")
        page_size = kwargs.get("pageSize")

        self.request_url = "/api/manager/videoQualityDetail"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"startTime": start_time, "endTime": end_time, "deviceName": device_name,
                               "malfunctionType": malfunction_type, "currentPage": current_page, "pageSize": page_size}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_camera_signal_loss_top5(self, **kwargs):
        start_time = kwargs.get("startTime")
        end_time = kwargs.get("endTime")
        areas = kwargs.get("area[]")

        self.request_url = "/api/manager/deviceSignalLoss"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"startTime": start_time, "endTime": end_time, "area[]": areas}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_camera_image_quality_top5(self, **kwargs):
        start_time = kwargs.get("startTime")
        end_time = kwargs.get("endTime")
        areas = kwargs.get("area[]")

        self.request_url = "/api/manager/historyMalfunctionType"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"startTime": start_time, "endTime": end_time, "area[]": areas}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_camera_info_with_people_count_event(self):
        self.request_url = "/api/peopleStatistics/cameraSelect"
        url = self.web_url + self.request_url
        self.request_method = "GET"

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response

    def get_realtime_people_count(self, **kwargs):
        camera_id = kwargs.get("cameraId")

        self.request_url = "/api/peopleStatistics/peopleCount"
        url = self.web_url + self.request_url
        self.request_method = "GET"
        self.request_params = {"cameraId": camera_id}

        response = HTTPRequest().http_request(method=self.request_method, url=url, headers=self.request_headers,
                                              params=self.request_params, cookies=self.cookies)
        return response
